<?php

namespace App\Admin\Controllers;

use Slowlyo\OwlAdmin\Admin;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Slowlyo\OwlAdmin\Controllers\AdminController;

class HomeController extends AdminController
{
    public function index()
    {
        $page = $this->basePage()->body([
            // 个人信息区域
            amis('flex')->justify('space-between')->alignItems('center')->items([
                // 左侧欢迎信息 - 占60%宽度
                amis('flex')->className('welcome-container')->alignItems('center')->items([
                    amis('image')->className('user-avatar')->src('/admin-assets/default-avatar.png'),
                    amis('flex')->className('user-info')->direction('column')->items([
                        amis('text')->className('user-name')->value('管理员'),
                        amis('text')->className('welcome-title')->value('欢迎回来，祝您工作愉快！')
                    ])
                ]),
                
                // 右侧快捷操作 - 占40%宽度
                amis('flex')->className('quick-actions-container')->justify('center')->alignItems('center')->items([
                    amis('button')->className('action-btn')->label('新建任务')->icon('fa fa-plus-circle')->level('primary'),
                    amis('button')->className('action-btn')->label('消息通知')->icon('fa fa-bell')->level('default'),
                    amis('button')->className('action-btn')->label('系统设置')->icon('fa fa-cog')->level('default')
                ])
            ])->className('header-section'),
            
            // 数据总览区域
            amis('grid')->columns([
                // 设备数量卡片
                amis('card')->body([
                    amis('flex')->items([
                        amis('icon')->className('stats-icon')->icon('fas fa-server'),
                        amis('flex')->className('stats-content')->direction('column')->justify('center')->alignItems('center')->items([
                            amis('text')->className('stats-number')->value('1,234'),
                            amis('text')->className('stats-label')->value('交换机总数')
                        ])
                    ])->justify('space-between')->alignItems('center')
                ])->className('stats-card device-card')->columnClassName('col-md-3'),
                
                // 客户数量卡片
                amis('card')->body([
                    amis('flex')->items([
                        amis('icon')->className('stats-icon')->icon('fas fa-users'),
                        amis('flex')->className('stats-content')->direction('column')->justify('center')->alignItems('center')->items([
                            amis('text')->className('stats-number')->value('567'),
                            amis('text')->className('stats-label')->value('客户总数')
                        ])
                    ])->justify('space-between')->alignItems('center')
                ])->className('stats-card customer-card')->columnClassName('col-md-3'),
                
                // 任务数量卡片
                amis('card')->body([
                    amis('flex')->items([
                        amis('icon')->className('stats-icon')->icon('fas fa-tasks'),
                        amis('flex')->className('stats-content')->direction('column')->justify('center')->alignItems('center')->items([
                            amis('text')->className('stats-number')->value('42'),
                            amis('text')->className('stats-label')->value('待处理任务')
                        ])
                    ])->justify('space-between')->alignItems('center')
                ])->className('stats-card task-card')->columnClassName('col-md-3'),
                
                // 总带宽卡片
                amis('card')->body([
                    amis('flex')->items([
                        amis('icon')->className('stats-icon')->icon('fas fa-tachometer-alt'),
                        amis('flex')->className('stats-content')->direction('column')->justify('center')->alignItems('center')->items([
                            amis('text')->className('stats-number')->value('128.5'),
                            amis('text')->className('stats-label')->value('总带宽 (Gbps)')
                        ])
                    ])->justify('space-between')->alignItems('center')
                ])->className('stats-card bandwidth-card')->columnClassName('col-md-3')
            ])->className('stats-overview'),
            
            // 待办任务区域
            amis('container')->body([
                amis('flex')->className('section-header')->justify('space-between')->alignItems('center')->items([
                    amis('flex')->className('section-title-wrapper')->alignItems('center')->items([
                        amis('icon')->className('section-icon')->icon('fas fa-clipboard-list'),
                        amis('text')->className('section-title')->value('待办任务')
                    ]),
                    amis('flex')->className('section-actions')->items([
                        amis('button')->level('primary')->size('sm')->icon('fa fa-plus')->class('pr-2')->label('新建任务'),
                        amis('button')->level('primary')->size('sm')->icon('fa fa-plus')->label('新建进度')
                    ])
                ]),
                
                // 任务卡片列表
                amis('grid')->columns([
                    // 任务卡片1 - 重要紧急
                    amis('card')->className('task-card urgent-important')->body([
                        amis('flex')->className('task-header')->justify('space-between')->alignItems('center')->items([
                            amis('tag')->className('priority-badge urgent')->label('重要-紧急'),
                            amis('flex')->className('vote-section')->items([
                                amis('button')->className('vote-btn up')->icon('fa fa-thumbs-up')->label('15'),
                                amis('button')->className('vote-btn down')->icon('fa fa-thumbs-down')->label('2')
                            ])
                        ]),
                        amis('flex')->className('task-content')->direction('column')->items([
                            amis('text')->className('task-title')->value('核心交换机升级维护'),
                            amis('flex')->className('task-meta')->direction('column')->items([
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fas fa-calendar'),
                                    amis('text')->value('开始时间：2024-01-20 14:00')
                                ]),
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fas fa-user'),
                                    amis('text')->value('负责人：张工程师')
                                ]),
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fa fa-target'),    
                                    amis('text')->value('目标：完成核心设备升级，确保网络稳定')
                                ])
                            ]),
                            amis('card')->className('task-progress')->body([
                                amis('flex')->className('progress-header')->justify('space-between')->alignItems('center')->items([
                                    amis('text')->value('最近进展'),
                                    amis('text')->className('progress-time')->value('2小时前')
                                ]),
                                amis('text')->className('progress-content')->value('已完成设备备份，正在进行固件升级...')
                            ]),
                            amis('flex')->className('task-footer')->justify('space-between')->alignItems('center')->items([
                                amis('flex')->className('schedule-value')->alignItems('center')->items([
                                    amis('text')->className('schedule-label')->value('调度值：'),
                                    amis('text')->className('schedule-number')->value('13')
                                ]),
                                amis('button')->label('查看详情')->icon('fa fa-eye')->level('primary')->size('sm')->className('view-details')
                            ])
                        ])
                    ])->columnClassName('col-md-6'),
                    
                    // 任务卡片2 - 重要不紧急
                    amis('card')->className('task-card important-not-urgent')->body([
                        amis('flex')->className('task-header')->justify('space-between')->alignItems('center')->items([
                            amis('tag')->className('priority-badge important')->label('重要-不紧急'),
                            amis('flex')->className('vote-section')->items([
                                amis('button')->className('vote-btn up')->icon('fa fa-thumbs-up')->label('8'),
                                amis('button')->className('vote-btn down')->icon('fa fa-thumbs-down')->label('1')
                            ])
                        ]),
                        amis('flex')->className('task-content')->direction('column')->items([
                            amis('text')->className('task-title')->value('客户网络架构优化方案'),
                            amis('flex')->className('task-meta')->direction('column')->items([
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fas fa-calendar'),
                                    amis('text')->value('开始时间：2024-01-22 09:00')
                                ]),
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fas fa-user'),
                                    amis('text')->value('负责人：李架构师')
                                ]),
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fa fa-target'),
                                    amis('text')->value('目标：设计新的网络架构，提升性能30%')
                                ])
                            ]),
                            amis('card')->className('task-progress')->body([
                                amis('flex')->className('progress-header')->justify('space-between')->alignItems('center')->items([
                                    amis('text')->value('最近进展'),
                                    amis('text')->className('progress-time')->value('1天前')
                                ]),
                                amis('text')->className('progress-content')->value('完成需求分析，正在制定技术方案...')
                            ]),
                            amis('flex')->className('task-footer')->justify('space-between')->alignItems('center')->items([
                                amis('flex')->className('schedule-value')->alignItems('center')->items([
                                    amis('text')->className('schedule-label')->value('调度值：'),
                                    amis('text')->className('schedule-number')->value('7')
                                ]),
                                amis('button')->label('查看详情')->icon('fa fa-eye')->level('primary')->size('sm')->className('view-details')
                            ])
                        ])
                    ])->columnClassName('col-md-6')
                ]),
                
                amis('grid')->columns([
                    // 任务卡片3 - 紧急不重要
                    amis('card')->className('task-card urgent-not-important')->body([
                        amis('flex')->className('task-header')->justify('space-between')->alignItems('center')->items([
                            amis('tag')->className('priority-badge urgent-minor')->label('紧急-不重要'),
                            amis('flex')->className('vote-section')->items([
                                amis('button')->className('vote-btn up')->icon('fa fa-thumbs-up')->label('5'),
                                amis('button')->className('vote-btn down')->icon('fa fa-thumbs-down')->label('3')
                            ])
                        ]),
                        amis('flex')->className('task-content')->direction('column')->items([
                            amis('text')->className('task-title')->value('办公网络打印机故障'),
                            amis('flex')->className('task-meta')->direction('column')->items([
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fas fa-calendar'),
                                    amis('text')->value('开始时间：2024-01-19 16:30')
                                ]),
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fas fa-user'),
                                    amis('text')->value('负责人：王技术员')
                                ]),
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fa fa-target'),
                                    amis('text')->value('目标：修复打印机网络连接问题')
                                ])
                            ]),
                            amis('card')->className('task-progress')->body([
                                amis('flex')->className('progress-header')->justify('space-between')->alignItems('center')->items([
                                    amis('text')->value('最近进展'),
                                    amis('text')->className('progress-time')->value('30分钟前')
                                ]),
                                amis('text')->className('progress-content')->value('已定位问题，正在更换网络模块...')
                            ]),
                            amis('flex')->className('task-footer')->justify('space-between')->alignItems('center')->items([
                                amis('flex')->className('schedule-value')->alignItems('center')->items([
                                    amis('text')->className('schedule-label')->value('调度值：'),
                                    amis('text')->className('schedule-number')->value('2')
                                ]),
                                amis('button')->label('查看详情')->icon('fa fa-eye')->level('primary')->size('sm')->className('view-details')
                            ])
                        ])
                    ])->columnClassName('col-md-6'),
                    
                    // 任务卡片4 - 不重要不紧急
                    amis('card')->className('task-card not-important-not-urgent')->body([
                        amis('flex')->className('task-header')->justify('space-between')->alignItems('center')->items([
                            amis('tag')->className('priority-badge normal')->label('不重要-不紧急'),
                            amis('flex')->className('vote-section')->items([
                                amis('button')->className('vote-btn up')->icon('fa fa-thumbs-up')->label('3'),
                                amis('button')->className('vote-btn down')->icon('fa fa-thumbs-down')->label('0')
                            ])
                        ]),
                        amis('flex')->className('task-content')->direction('column')->items([
                            amis('text')->className('task-title')->value('设备标签整理归档'),
                            amis('flex')->className('task-meta')->direction('column')->items([
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fas fa-calendar'),
                                    amis('text')->value('开始时间：2024-01-25 10:00')
                                ]),
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fas fa-user'),
                                    amis('text')->value('负责人：陈助理')
                                ]),
                                amis('flex')->className('meta-item')->alignItems('center')->justify('start')->items([
                                    amis('icon')->icon('fa fa-target'),
                                    amis('text')->value('目标：整理机房设备标签，建立档案')
                                ])
                            ]),
                            amis('card')->className('task-progress')->body([
                                amis('flex')->className('progress-header')->justify('space-between')->alignItems('center')->items([
                                    amis('text')->value('最近进展'),
                                    amis('text')->className('progress-time')->value('3天前')
                                ]),
                                amis('text')->className('progress-content')->value('已完成A区设备标签整理，准备进入B区...')
                            ]),
                            amis('flex')->className('task-footer')->justify('space-between')->alignItems('center')->items([
                                amis('flex')->className('schedule-value')->alignItems('center')->items([
                                    amis('text')->className('schedule-label')->value('调度值：'),
                                    amis('text')->className('schedule-number')->value('1')
                                ]),
                                amis('button')->label('查看详情')->icon('fa fa-eye')->level('primary')->size('sm')->className('view-details')
                            ])
                        ])
                    ])->columnClassName('col-md-6')
                ])
            ])->className('tasks-section')
        ]);
        
        return $page->css([
            '.header-section' => [
                'margin-bottom' => '24px',
                'padding' => '24px',
                'background' => 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
                'border-radius' => '12px',
                'display' => 'flex',
                'justify-content' => 'space-between',
                'align-items' => 'center'
            ],
            '.welcome-container' => [
                'width' => '60%',
                'display' => 'flex',
                'align-items' => 'center',
                'gap' => '16px'
            ],
            '.cxd-Image-image' => [
                'width' => '50px !important',
                'height' => '50px !important',
                'border-radius' => '50%',
                'border' => '3px solid rgba(255,255,255,0.3)',
                'object-fit' => 'cover',
                'object-position' => 'center'
            ],
            '.user-info' => [
                'display' => 'flex',
                'flex-direction' => 'column',
                'gap' => '4px'
            ],
            '.user-name' => [
                'color' => 'white',
                'margin' => '0',
                'font-size' => '24px',
                'font-weight' => '700'
            ],
            '.welcome-title' => [
                'font-size' => '14px',
                'font-weight' => '400',
                'color' => 'rgba(255,255,255,0.8)',
                'margin' => '0'
            ],
            '.quick-actions-container' => [
                'width' => '40%',
                'display' => 'flex',
                'justify-content' => 'center',
                'align-items' => 'center',
                'gap' => '12px'
            ],
 
            '.stats-card' => [
                'background' => '#ffffff',
                'border-radius' => '5px',
                'padding' => '24px 24px 0 24px',
                'border' => '1px solid #e2e8f0',
                'height' => '100%',
                'display' => 'flex',
                'position' => 'relative'
            ],
            '.stats-card::before' => [
                'content' => '""',
                'position' => 'absolute',
                'top' => '0',
                'left' => '0',
                'right' => '0',
                'height' => '4px',
                'background' => 'linear-gradient(90deg, #667eea, #764ba2)',
                'border-radius' => '12px 12px 0 0'
            ],
            '.stats-card.device-card::before' => [
                'background' => 'linear-gradient(90deg, #3b82f6, #1d4ed8)'
            ],
            '.stats-card.customer-card::before' => [
                'background' => 'linear-gradient(90deg, #10b981, #059669)'
            ],
            '.stats-card.task-card::before' => [
                'background' => 'linear-gradient(90deg, #f59e0b, #d97706)'
            ],
            '.stats-card.bandwidth-card::before' => [
                'background' => 'linear-gradient(90deg, #ef4444, #dc2626)'
            ],
            '.stats-icon' => [
                'font-size' => '48px',
                'color' => '#667eea',
                'margin-right' => '16px'
            ],
            '.stats-number' => [
                'font-size' => '32px',
                'font-weight' => '700',
                'color' => '#1e293b',
                'margin' => '0',
                'line-height' => '1.2'
            ],
            '.stats-label' => [
                'font-size' => '14px',
                'font-weight' => '500',
                'color' => '#64748b',
                'margin' => '4px 0 8px 0'
            ],

            '.task-card' => [
                'background' => '#ffffff',
                'border-radius' => '12px',
                'padding' => '24px 24px 0 24px',
                'margin-bottom' => '20px',
                'border' => '1px solid #e2e8f0',
                'display' => 'flex',
                'flex-direction' => 'column'
            ],
            '.task-card.urgent-important' => [
                'border-left' => '4px solid #ef4444'
            ],
            '.task-card.important-not-urgent' => [
                'border-left' => '4px solid #f59e0b'
            ],
            '.task-card.urgent-not-important' => [
                'border-left' => '4px solid #3b82f6'
            ],
            '.task-card.not-important-not-urgent' => [
                'border-left' => '4px solid #10b981'
            ],
            '.task-title' => [
                'font-size' => '18px',
                'font-weight' => '700',
                'color' => '#1e293b',
                'margin' => '0 0 16px 0',
                'line-height' => '1.4',
                'display' => 'block'
            ],
            '.priority-badge' => [
                'padding' => '6px 12px',
                'border-radius' => '16px',
                'font-size' => '12px',
                'font-weight' => '600',
                'text-transform' => 'uppercase',
                'letter-spacing' => '0.5px'
            ],
            '.priority-badge.urgent' => [
                'background' => '#fecaca',
                'color' => '#7f1d1d'
            ],
            '.priority-badge.important' => [
                'background' => '#fed7aa',
                'color' => '#9a3412'
            ],
            '.priority-badge.urgent-minor' => [
                'background' => '#bfdbfe',
                'color' => '#1e3a8a'
            ],
            '.priority-badge.normal' => [
                'background' => '#bbf7d0',
                'color' => '#14532d'
            ],
            '.vote-btn' => [
                'background' => '#f8fafc',
                'border' => '1px solid #cbd5e1',
                'border-radius' => '6px',
                'padding' => '6px 12px',
                'font-size' => '12px',
                'font-weight' => '500',
                'margin-right' => '8px'
            ],
            '.vote-btn:hover' => [
                'background' => '#e2e8f0'
            ],
            '.vote-btn.up:hover' => [
                'background' => '#dcfce7',
                'color' => '#166534',
                'border-color' => '#16a34a'
            ],
            '.vote-btn.down:hover' => [
                'background' => '#fee2e2',
                'color' => '#991b1b',
                'border-color' => '#dc2626'
            ],
            '.task-progress' => [
                'background' => '#f8fafc',
                'border-radius' => '8px',
                'margin' => '16px 0',
                'border' => '1px solid #e2e8f0'
            ],
            '.progress-content' => [
                'color' => '#475569',
                'font-size' => '14px',
                'line-height' => '1.5',
                'font-weight' => '400'
            ],
            '.section-title,.section-icon' => [
                'font-size' => '24px',
                'font-weight' => '700',
                'color' => '#1e293b',
                'margin' => '24px 12px 12px 0'
            ],
            '.section-icon' => [
                'color' => 'red',
            ],
            '.meta-item' => [
                'font-size' => '14px',
                'font-weight' => '400',
                'color' => '#475569',
                'line-height' => '1.8'
            ],
             '.meta-item >.fas,.meta-item >.fa' => [
                'margin-right' => '5px',
            ],

            
            
        ]);
    }


}
